package com.google.code.puertorico

object BoardState {

  def initialPlantations: List[Plantation] = List(CornPlantation(false), SugarPlantation(false));

  def initialBuildings: List[Building] = List(SmallIndigoPlant(0), SmallIndigoPlant(0), SmallSugarMill(0));

  def initialQuarries: List[QuarryPlantation] = List(QuarryPlantation(false), QuarryPlantation(false), QuarryPlantation(false))

  def initialShips: List[Ship] = List(Ship(None, 0, 4), Ship(None, 0, 5), Ship(None, 0, 6));

  def initialResources: Resources = Resources(gold = 100, corn = 11, indigo = 11, sugar = 11, tobacco = 11, coffee = 11);

  // TODO: Hack about active strategy card?
  def initial(players: List[Player]): BoardState
  = BoardState(players = players, activePlayer = players.head, governor = players.head,
    availablePlantations = initialPlantations, availableBuildings = initialBuildings,
    availableQuarries = initialQuarries, ships = initialShips, availableResources = initialResources,
    availableStrategyCards = StrategyCard.initial,
    activeStrategyCard = Prospector(0), slaveShip = 5, availableSlaves = 50, // TODO: Hacks
    tradingHouse = TradingHouse.initialTradingHouse
  )

}

case class BoardState(players: List[Player],
                      activePlayer: Player,
                      governor: Player,
                      availablePlantations: List[Plantation],
                      availableBuildings: List[Building],
                      availableQuarries: List[QuarryPlantation],
                      ships: List[Ship],
                      availableResources: Resources,
                      availableStrategyCards: List[StrategyCard],
                      activeStrategyCard: StrategyCard,
                      slaveShip: Int,
                      availableSlaves: Int,
                      tradingHouse: TradingHouse) {

  // the player just before the governor (i.e. the player to make his move last)
  def lastPlayerBeforeGovernor: Boolean = throw new RuntimeException();

  def activePlayerHasStrategyCard: Boolean = throw new RuntimeException();

  // the player after the current governor
  def nextGovernor: Player = throw new RuntimeException();

  def nextActivePlayer: Player = throw new RuntimeException();

  def moveToNextPlayer(): BoardState = throw new RuntimeException();

  def buyBuilding(building: Building): BoardState = {
    copy(activePlayer = activePlayer.buyBuilding(building), availableBuildings = availableBuildings - building);
  }

  def takeActionCard(card: StrategyCard): BoardState = {
    val newState = copy(activeStrategyCard = card, availableStrategyCards = availableStrategyCards - card);
    newState.activePlayerTakeGold(card.bonus);
  }

  // TODO; Naming
  def activePlayerTakeGold(amount: Int): BoardState = {
    copy(activePlayer = activePlayer.takeGold(amount));
  }


  def tradingHouseFull: Boolean = tradingHouse.isFull;


}
